<template>
  <div>
    <div class="main_content">
      <el-form id="s_form" :model="searchForm" :inline="true" ref="searchForm">
        <el-form-item prop="searchText">
          <el-input
            style="width:200px;"
            clearable
            v-model="searchForm.searchText"
            placeholder="请输项目/编号查询"
            @keydown.enter.native="doSearch()"
          ></el-input>
          <el-button type="primary" @click="doSearch()" class="added">
            <i class="el-icon-search"></i>
            搜索
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="showBack" @click="doReturn()">
            <i class="el-icon-back"></i>
            返回
          </el-button>
        </el-form-item>
      </el-form>
      <myTable
        style="margin-top:15px"
        auto='getAllList'
        :height='Height-210'
        min-width='130'
        :myColumn=tableProp
        ahide='index,checkbox,mySplitPage,tooltip,background'
        hide="checkbox"
        slots='操作,206,right'
        select='console'
        @header-click='console'
        hook:created=' myTable.tableData = tableData '
      >
        <template slot-scope='button'>
          <el-button v-if='button.scope.row.updateState==1'  type="success" size="mini" @click="handleDetail(button.scope.$index, button.scope.row)">
            <i class="el-icon-view"></i>
            修改记录
          </el-button>
          <el-button
            v-if='button.scope.row.updateState==0'
            :disabled='button.scope.row.updateState==0'
            type="info"
            size="mini"
            @click="handleDetail(button.scope.$index, button.scope.row)"
          >
            <i class="el-icon-view"></i>
            修改记录
          </el-button>
          <el-button type="primary" size="mini" @click="record(button.scope.$index, button.scope.row)">
            <i class="el-icon-bell"></i>
            报警记录
          </el-button>
        </template>
      </myTable>
    </div>
  </div>
</template>
<script>
import myhttp, {
  isEmpty,
  msgError,
  msgSuccess,
  msgWarning
} from "../../utils/myhttp";
import qs from "qs";
import api from "../../utils/api";
export default {
  data() {
    return {
      loading: "",
      active_crumb: "active_crumb", //面包屑当前颜色
      tableHeaderStyle: {
        //表头样式
        "background-color": "rgb(242,242,242)"
      },
      multipleSelection: [], //多选
      theRow: {}, //当前行数据
      theIndex: 0, //当前下标
      theAdd: {}, //新增数据
      hasMultiDelete: false, //是否多选
      searchForm:{
        searchText: "", //搜索字段
      },
      myTotal: 1, //分页总条数，默认1
      currentPage: 1, //初始化当前页
      nowPage: 1, //当前页
      thePageSize: 15, //每页条数
      tableData: [],
      tableProp: [
        { label: "项目", prop: "projectName" , sort: true },
        { label: "旁站", prop: "stationType", sort: true, width:180, html(prop) {
          return $.class[prop]||'';
          }
        },
        { label: "编号", prop: "stationNo", asort: true },// projectNumber
        { label: "旁站开始时间", prop: "startTime", sort: true ,width:180},
        { label: "旁站结束时间", prop: "endTime", sort: true ,width:180},
        { label: "职位", prop: "projectUserInfoList", html(prop,row){
          return Return(prop,(a,v)=>a+'、'+v.positionName).slice(1);
        } },
        { label: "旁站人", prop: "createPerson" },
      ],
      alldata:[],
      showBack:false,
      page: {
        firstInto: true,
        num: '',
        limit: '',
        pageNum: '',
        pageSize: ''
      }
    };
  },
  components: {},
  methods: {
    doReturn(){
      this.$refs.searchForm.resetFields()
      this.getAllList();
      this.showBack = false;
    },
    //报警值记录
    record(index,row){
      this.$router.push({
        name:'recordDetails',
        params: {
          project_name: row.projectName,
          programme_name: row.programmeName,
          project_number: row.projectNumber,
          stationId: row.stationId,
          inspector_name:row.inspectorName,
          station_type:row.stationType,
          project_id:row.projectId,
          pageNum: this.page.pageNum,
          pageSize: this.page.pageSize
        }
      });
    },
    handleDetail(index,row) {
      // var data = row.projectUserInfoList || [];
      // var str = '';
      // for(var i = 0; i < data.length; i++){
      //   this.alldata = data[i];
      //   if(data[i].positionType === '1'){
      //     this.user_name = data[i].userName;
      //   }
      // };
      this.$router.push({
        name:"logDetails",
        params: {
          // user_name: this.userName,
          // user_account: this.phoneNumber,
          // user_all: this.user_name,
          project_name: row.projectName,
          programme_name: row.programmeName,
          project_number: row.projectNumber,
          stationId: row.stationId,
          inspector_name:row.inspectorName,
          pageNum: this.page.pageNum,
          pageSize: this.page.pageSize
        },
      });
    },
    doSearch() {
      //搜索方法
      this.getAllList();
      this.showBack = true;
    },
    handleCurrentChange(val) {
      //分页查询
      this.nowPage = val;
      this.getAllList();
    },
    openLoading() {
      //loading请求等待
      this.loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },
    getAllList: async function(pageNum,pageSize) {
      this.page.pageNum = this.page.firstInto ? this.page.num || pageNum : pageNum
      this.page.pageSize = this.page.firstInto ? this.page.limit || pageSize : pageSize
     var res = await $.post('getAllStationByuserId',{
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize,
        searchText: this.searchForm.searchText,//搜索文本
        userId:localStorage.getItem("userId"),
      });
      if (this.page.firstInto && this.page.num) {
        res.currentPage = this.page.num
        res.limitTiao = this.page.limit
      }
      this.page.firstInto = false
      if(!res.success) return $.msgError(res.msg||'error!');
      $return('__',res);
    }
  },
  created() {
    var P = this.$route.params;
    // console.error(P);
    if (!G.isEmpty(P)) {
      this.page.num = P.pageNum || ''
      this.page.limit = P.pageSize || ''
    }
    ;
  },
  mounted() {}
};
</script>
<style scoped>

</style>


